//
//  YYEWelcomeViewController.swift
//  weibo14
//
//  Created by mac on 16/3/6.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SDWebImage

class YYEWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }

    private func setupUI() {
    
        view.backgroundColor = UIColor.whiteColor()
        
       // 添加子控件
       view.addSubview(headImage)
       view.addSubview(messageLabel)
        
       // 添加约束
       headImage.snp_makeConstraints { (make) -> Void in
        
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(200)
            make.size.equalTo(CGSizeMake(90,90))
        
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(20)
            
        }
    }
    
    
    // 将要显示是做动画
    override func viewDidAppear(animated: Bool){
        super.viewDidAppear(animated)
    
        // 先更新约束
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        
        // Dampin 阻尼: 0 -> 1
        // Velocity: 弹簧的初始速度
        //执行动画
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
        
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
            NSNotificationCenter.defaultCenter().postNotificationName(YYESwitchRootVCNotification, object: self)
                
        }
    
    }
    

    
    

    // MARK: 懒加载控件
    
    lazy var headImage:UIImageView = {
    
        let v = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        v.layer.cornerRadius = 45
        v.layer.masksToBounds = true
        
        let headImageUrlString = YYEUserAccountViewModel.sharedAccountViewModel.account?.avatar_large

        
        v.sd_setImageWithURL(NSURL(string: headImageUrlString!), placeholderImage: UIImage(named: "avatar_default_big"))
        
        return v
    }()
    
    
    lazy var messageLabel:UILabel = {
    
        let v = UILabel(textColor: UIColor.grayColor(), fontSzie: 16)
        
        v.text = "欢迎回来"
        v.alpha = 0
        v.sizeToFit()
        
        return v
        
    }()
    
}







